
package com.studiofortress.sf.util.structure;

import com.studiofortress.sf.structure.Actor;
import com.studiofortress.sf.graphics.GraphicsGL;
import com.studiofortress.sf.graphics.GLTexture;

/**
 *
 * @author Joseph Lenton
 */
public class ImageActor<G extends GraphicsGL> extends Actor<G>
{
    private GLTexture image;
    
    public ImageActor()
    {
        this( null );
    }
    
    public ImageActor(final GLTexture image)
    {
        this(image, 0, 0);
    }
    
    public ImageActor(final GLTexture image, final float x, final float y)
    {
        super(x, y);

        this.image = image;
        
        if (image != null) {
            setWidth(  image.getWidth()  );
            setHeight( image.getHeight() );
        }
    }

    /**
     * @return The image this Actor uses when drawing, or null if there is no image.
     */
    public GLTexture getImage()
    {
        return image;
    }
    
    /**
     * @param image The new image this Actor will use when drawing, or null for no image.
     */
    public void setImage(GLTexture image)
    {
        this.image = image;
        if (image == null) {
            setWidth(1);
            setHeight(1);
        } else {
            setWidth(image.getWidth());
            setHeight(image.getHeight());
        }
    }
    
    /**
     * Draws this Actors image midhandled at the Actors current location.
     * @param g The Graphics2D to draw this image too.
     */
    @Override
    public void paint(G g)
    {
        final GLTexture tex = getImage();
        if (tex != null) {
            g.drawTexture( tex, getX(), getY(), true );
        }
    }
}
